<template>
  <ele-page>
    <el-row>
      <el-col :span="4">
        <el-card shadow="hover" style="cursor: pointer" @click="openModal">
          <div class="card-img">
            <img
              src="@/assets/counsellor/counsellor_detail.png"
              alt="就业明细报表"
            />
          </div>
          <div class="card-title">就业明细报表</div>
        </el-card>
      </el-col>
    </el-row>
    <report-modal v-model="showModal" :url="url"></report-modal>
  </ele-page>
</template>
<script setup>
  import { getConfigKey } from '@/api/system/config';
  import { computed, ref } from 'vue';
  import ReportModal from './components/report-modal.vue';
  import { useUserStore } from '@/store/modules/user';

  const userStore = useUserStore();
  //获取当前用户的信息
  const loginUser = computed(() => userStore.info ?? {});

  const reportBaseUrl = ref(''); //报表基础url
  const selectReportBaseUrl = () => {
    getConfigKey('report_base_url').then((res) => {
      reportBaseUrl.value = res.msg;
    });
  };
  selectReportBaseUrl();

  const counsellorEmploymentStatisticsReport = ref(''); //辅导员明细
  const selectCounsellorEmploymentStatisticsReport = () => {
    getConfigKey('counsellor_employment_statistics_report').then((res) => {
      counsellorEmploymentStatisticsReport.value = res.msg;
      // console.log(res.msg);
    });
  };
  selectCounsellorEmploymentStatisticsReport();

  const reportNoPage = ref(''); //报表不分页
  const selectReportNoPage = () => {
    getConfigKey('report_no_page').then((res) => {
      reportNoPage.value = res.msg;
      console.log(res.msg);
    });
  };
  selectReportNoPage();

  const year = ref(''); //当前毕业年份
  const selectYear = () => {
    getConfigKey('current.graduation.year').then((res) => {
      year.value = res.msg;
      console.log(res.msg);
    });
  };
  selectYear();

  const showModal = ref(false);
  const url = ref('');
  const openModal = () => {
    //window.open(reportBaseUrl.value + "&year=" + props.data.fileYear + "&date=" + props.data.fileTime);
    url.value =
      reportBaseUrl.value +
      counsellorEmploymentStatisticsReport.value +
      reportNoPage.value +
      '&year=' +
      year.value +
      '&code=' +
      loginUser.value.userName;
    //console.log(loginUser.value);
    console.log(url.value);
    const newWindow = window.open(
      url.value,
      '_blank',
      'top=0,left=0,location=no,status=no'
    );
    newWindow.moveTo(0, 0);
    newWindow.resizeTo(screen.width, screen.height);
  };
</script>
<style scoped>
  .card-img {
    text-align: center;

    img {
      width: 100px;
    }
  }

  .card-title {
    font-size: 16px;
    text-align: center;
    font-family: 'Microsoft YaHei';
    font-weight: bold;
  }
</style>
